package com.stone.framework.core.entity;

import java.io.Serializable;
import java.time.LocalDateTime;

import javax.persistence.Column;
import javax.persistence.EntityListeners;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.MappedSuperclass;
import javax.persistence.Version;

import org.springframework.data.annotation.CreatedBy;
import org.springframework.data.annotation.CreatedDate;
import org.springframework.data.annotation.LastModifiedBy;
import org.springframework.data.annotation.LastModifiedDate;
import org.springframework.data.jpa.domain.support.AuditingEntityListener;

import com.baomidou.mybatisplus.annotation.FieldFill;
import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableId;

@MappedSuperclass
@EntityListeners(AuditingEntityListener.class)
public abstract class CommonEntity implements Serializable {

    private static final long serialVersionUID = -6140073661387545794L;

    /**
     * 主键
     */
    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    // @GenericGenerator(strategy = "uuid", name = "auto-uuid")
    @TableId(value = "ID", type = IdType.AUTO)
    @Column(name = "ID")
    private Long id;

    /**
     * 创建时间
     */
    @CreatedDate
    @TableField(value = "CREATE_DATE", fill = FieldFill.INSERT)
    @Column(name = "CREATE_DATE")
    private LocalDateTime createDate;

    /**
     * 创建人
     */
    @CreatedBy
    @TableField(value = "CREATE_USER", fill = FieldFill.INSERT)
    @Column(name = "CREATE_USER")
    private String createUser;

    /**
     * 最后更新时间
     */
    @LastModifiedDate
    @TableField(value = "UPDATE_DATE", fill = FieldFill.INSERT_UPDATE)
    @Column(name = "UPDATE_DATE")
    private LocalDateTime updateDate;

    /**
     * 最后更新人
     */
    @LastModifiedBy
    @TableField(value = "UPDATE_USER", fill = FieldFill.INSERT_UPDATE)
    @Column(name = "UPDATE_USER")
    private String updateUser;

    @Version
    @com.baomidou.mybatisplus.annotation.Version
    @Column(name = "VERSION")
    @TableField(value = "VERSION", fill = FieldFill.INSERT)
    private Long version;

    public Long getId() {
        return id;
    }

    public void setId(Long id) {
        this.id = id;
    }

    public LocalDateTime getCreateDate() {
        return createDate;
    }

    public void setCreateDate(LocalDateTime createDate) {
        this.createDate = createDate;
    }

    public String getCreateUser() {
        return createUser;
    }

    public void setCreateUser(String createUser) {
        this.createUser = createUser;
    }

    public LocalDateTime getUpdateDate() {
        return updateDate;
    }

    public void setUpdateDate(LocalDateTime updateDate) {
        this.updateDate = updateDate;
    }

    public String getUpdateUser() {
        return updateUser;
    }

    public void setUpdateUser(String updateUser) {
        this.updateUser = updateUser;
    }

    public Long getVersion() {
        return version;
    }

    public void setVersion(Long version) {
        this.version = version;
    }

    @Override
    public String toString() {
        return "[id=" + id + ", createDate=" + createDate + ", createUser=" + createUser + ", updateDate=" + updateDate
            + ", updateUser=" + updateUser + ", version=" + version + "]";
    }

}
